import { request } from '../../utils/request'
import type { Post, ApiResponse } from '../../types/app.d'

/**
 * 获取岗位列表
 */
export const getPostList = (params: {
  page: number
  pageSize: number
  name?: string
  code?: string
  status?: number
  beginTime?: string
  endTime?: string
}) => {
  return request.get<ApiResponse<{
    list: Post[]
    total: number
  }>>('/system/post/list', { params })
}

/**
 * 获取岗位详情
 */
export const getPostInfo = (id: string) => {
  return request.get<ApiResponse<Post>>(`/system/post/${id}`)
}

/**
 * 创建岗位
 */
export const createPost = (data: Omit<Post, 'id' | 'createTime' | 'updateTime'>) => {
  return request.post<ApiResponse>('/system/post', data)
}

/**
 * 更新岗位
 */
export const updatePost = (id: string, data: Partial<Omit<Post, 'id' | 'createTime'>>) => {
  return request.put<ApiResponse>(`/system/post/${id}`, data)
}

/**
 * 删除岗位
 */
export const deletePost = (id: string) => {
  return request.delete<ApiResponse>(`/system/post/${id}`)
}

/**
 * 批量删除岗位
 */
export const batchDeletePost = (ids: string[]) => {
  return request.delete<ApiResponse>('/system/post/batch', { data: { ids } })
}

/**
 * 修改岗位状态
 */
export const changePostStatus = (id: string, status: number) => {
  return request.put<ApiResponse>(`/system/post/${id}/status`, { status })
}

/**
 * 获取所有岗位（用于选择器）
 */
export const getAllPosts = () => {
  return request.get<ApiResponse<Post[]>>('/system/post/all')
}